<?php
class DeleteFilter extends CFilter{
	protected function preFilter($filterChain)
    {
    	if($filterChain->action->getId()!='delete') return true;//不是删除操作
    	$con_id=$filterChain->controller->getId();
    	$dc=Yii::app()->params['delete_constraint'];
    	if(!isset($dc[$con_id])||!isset($_GET['id'])) return true;//未定义此关联项
    	$error_info=array();
    	$del_table=$dc[$con_id];
    	foreach($del_table as $n=>$dt){
    		$model=CActiveRecord::model($dt['table']);
    		if($model->exists(array('condition'=>$dt['fk_index'].'='.$_GET['id'].' and '.$dt['other']))){
    			$error_info[]=$n;
    		}
    	}
    	if(empty($error_info)) return true;//没有与要删除的信息有关联
    	unset($_GET['id']);
		$filterChain->controller->redirect(array('admin')+$_GET+array('constraintMess'=>implode(',',$error_info)));
		return false;
    }
	
}
?>